using System.Data.SqlTypes;
using System;
using UnityEngine;

namespace BuildingSystem.Scripts
{
    public class PlayerInput : MonoBehaviour
    {
        public Action OnMouseMoved;

        public Action OnLeftMouseButtonClicked;
        public Action OnRightMouseButtonClicked;

        public Action OnEscapePressed;
        public Action OnDeletePressed;

        public Vector3 MousePosition => _currentMousePosition;

        private Vector3 _currentMousePosition;
        private Vector3 _previousMousePosition = Vector3.zero;

        private void Update()
        {
            _currentMousePosition = Input.mousePosition;
            if (_currentMousePosition - _previousMousePosition != Vector3.zero)
            {
                OnMouseMoved?.Invoke();
                _previousMousePosition = _currentMousePosition;
            }

            if (Input.GetMouseButtonDown(0))
            {
                OnLeftMouseButtonClicked?.Invoke();
                OnMouseMoved?.Invoke();
            }
            if (Input.GetMouseButtonDown(1))
            {
                OnRightMouseButtonClicked?.Invoke();
                OnMouseMoved?.Invoke();
            }

            if (Input.GetKeyDown(KeyCode.Escape))
                OnEscapePressed?.Invoke();
            if (Input.GetKeyDown(KeyCode.Delete))
                OnDeletePressed?.Invoke();
        }
    }
}